package leetcode.editor.cn;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 电话号码的字母组合
 * @author qulq
 * @date 2024-07-07 13:57:04
 */
public class T17_LetterCombinationsOfAPhoneNumber{
	 public static void main(String[] args) {
	 	 //测试代码
	 	 Solution solution = new T17_LetterCombinationsOfAPhoneNumber().new Solution();
	 }
	 
//力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {

	List<String> ans = new ArrayList<>();
	Map<Character, char[]> map = new HashMap<>();

	public List<String> letterCombinations(String digits) {

		map.put('2', new char[]{'a', 'b', 'c'});
		map.put('3', new char[]{'d', 'e', 'f'});
		map.put('4', new char[]{'g', 'h', 'i'});
		map.put('5', new char[]{'j', 'k', 'l'});
		map.put('6', new char[]{'m', 'n', 'o'});
		map.put('7', new char[]{'p', 'q', 'r', 's'});
		map.put('8', new char[]{'t', 'u', 'v'});
		map.put('9', new char[]{'w', 'x', 'y', 'z'});

		if (digits == null || digits.length() == 0) {
			return ans;
		}
		backtracking(digits, 0, "");
		return ans;
    }

	private void backtracking(String digits, int idx, String curr) {
		if (idx == digits.length()) {
			ans.add(curr);
			return;
		}
		for (char c : map.get(digits.charAt(idx))) {
			backtracking(digits, idx + 1, curr + c);
		}

	}
}
//leetcode submit region end(Prohibit modification and deletion)

}